package com.software.glide;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;


public class MainActivity extends AppCompatActivity {

    private ImageView iv_avatar;
    private Button btn_show;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initViews();
        btn_show.setOnClickListener(v -> {
            //使用Glide获取网络图片
            Glide.with(this)
//                    .asGif() // 加载动图
                    .asBitmap() // 加载静态图片
                    .load("https://ts1.tc.mm.bing.net/th/id/R-C.323364ebc9d2a1c484c59d42461e45f7?rik=WURNM7Wn2MEVQA&riu=http%3a%2f%2fgovpic.qhnews.com%2f0%2f10%2f02%2f10%2f10021008_965321.png&ehk=Z8OtYOXZzNQ3OHNlvDoVtle0HrF4Ot1Yk%2fT1FfTj4vE%3d&risl=&pid=ImgRaw&r=0")
                    .placeholder(R.mipmap.loading) // 加载中的状态
                    .error(R.mipmap.loading_error) // 加载失败
                    .fallback(R.mipmap.empty) // 加载null状态
                    .diskCacheStrategy(DiskCacheStrategy.ALL) // 缓存策略
                    .into(iv_avatar);

            GlideApp.with(this)
                    .load("https://ts1.tc.mm.bing.net/th/id/R-C.323364ebc9d2a1c484c59d42461e45f7?rik=WURNM7Wn2MEVQA&riu=http%3a%2f%2fgovpic.qhnews.com%2f0%2f10%2f02%2f10%2f10021008_965321.png&ehk=Z8OtYOXZzNQ3OHNlvDoVtle0HrF4Ot1Yk%2fT1FfTj4vE%3d&risl=&pid=ImgRaw&r=0")
                    .defaultImage()
                    .into(iv_avatar);

        });


    }

    private void initViews() {
        iv_avatar = findViewById(R.id.iv_avatar);
        btn_show = findViewById(R.id.btn_show);
    }
}